package cn.engage.config;

import cn.engage.filter.RequestTimeFilter;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration // 和RequestTimeFilter，LoginFilter一起使用，登录
public class RequestTimeFilterConfig {

    // 配置Filter作用于那个访问规则上
    @Bean
    public RouteLocator customerRouteLocator(RouteLocatorBuilder builder) {
    return builder.routes().route(r -> r.path("/itsource/pay/**")
      //去掉1个前缀
      .filters(f -> f.stripPrefix(2)
        .filter(new RequestTimeFilter())
        .addResponseHeader("X-Response-test", "test"))
      .uri("lb://pay-server")
      .order(0)
      .id("test-RequestTimeFilter")
    ).build();
  }
}
